<template>
    <div style="padding: 10px;">
        <el-form :model="queryParams" ref="queryForm" class="queryForm" :inline="true" v-show="showSearch"
                 @submit.native.prevent>
            <el-form-item label="字段" desc="" prop="filedName">
                <el-input v-model.trim="queryParams.filedName" placeholder="" clearable size="small"
                          style="width:120px;" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="字段中文" desc="" prop="filedNameChinese">
                <el-input v-model.trim="queryParams.filedNameChinese" placeholder="" clearable size="small"
                          style="width:120px;" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="字段类型" desc="" prop="filedType">
                <dic-select v-model="queryParams.filedType" :code="dicInner.g_field_filedType" placeholder="" clearable
                            size="small" style="width:120px;" @keyup.enter.native="handleQuery" />
            </el-form-item>
            <!--  <el-form-item label="" desc="" prop="gTableId">
                  <el-input v-model.trim="queryParams.gTableId" placeholder="" clearable size="small" style="width:120px;"
                            @keyup.enter.native="handleQuery" />
              </el-form-item>-->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @submit.native.prevent @click="handleQuery">
                    搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5" class="buttonsRow">
                <el-button type="primary" size="small" plain @click="()=>triggerModify()">新增</el-button>
            </el-col>
            <right-toolbar @layout="(_obj)=>columnsHidden=_obj" :showSearch.sync="showSearch"
                           @queryTable="getInfoList"></right-toolbar>
        </el-row>
        <section class="tablecontainer">
            <el-table border ref="multipleTable" :data="dataList" size="mini" class="tabletop" tooltip-effect="dark"
                      style="width: 100%" @selection-change="rows=>{         selectRows=rows      }"
                      @row-click="row=>{          tableRowClickOnece(row,'multipleTable')      }"
                      :row-class-name="tableRowClassName"
                      @row-dblclick="row=>{
                                 $emit('success',row)
                              }"
                      >
                <el-table-column type="selection" width="40" align="center"></el-table-column>
                <el-table-column label="操作" width="55" align="center">
                    <template slot-scope="scope">
                        <el-popover placement="top-start" title="操作" width="222" trigger="hover">
                            <div>
                                <el-button size="mini" type="text" icon="el-icon-edit"
                                           @click="()=>triggerModify(scope.row)"> 修改
                                </el-button>
                                <el-button size="mini" type="text" icon="el-icon-notebook-1"
                                           @click="()=>openLog(scope.row)">变更日志
                                </el-button>
                                <el-button size="mini" type="text" icon="el-icon-delete"
                                           @click="()=>handleDelete(scope.row)">删除
                                </el-button>
                            </div>
                            <el-button slot="reference" type="text">操作</el-button>
                        </el-popover>
                    </template>
                </el-table-column>
                <el-table-column v-if="!columnsHidden['filedName']" label="字段" prop="filedName" min-width="120px;">
                    <template slot-scope="scope">
                        <div> {{scope.row.filedName}}</div>
                    </template>
                </el-table-column>
                <el-table-column v-if="!columnsHidden['filedNameChinese']" label="字段中文" prop="filedNameChinese"
                                 min-width="120px;">
                    <template slot-scope="scope">
                        <div> {{scope.row.filedNameChinese}}</div>
                    </template>
                </el-table-column>
                <el-table-column v-if="!columnsHidden['filedType']" label="字段类型" prop="filedType" min-width="120px;">
                    <template slot-scope="scope">
                        <dic-tag :code="dicInner.g_field_filedType" v-model="scope.row.filedType"></dic-tag>
                    </template>
                </el-table-column>
                <!--  <el-table-column v-if="!columnsHidden['gTableId']" label="" prop="gTableId" min-width="120px;">
                      <template slot-scope="scope">
                          <div> {{scope.row.gTableId}}</div>
                      </template>
                  </el-table-column>-->
                <el-table-column label="添加时间/人" prop="add_time/add_user" v-if="!columnsHidden['add_time/add_user']">
                    <template slot-scope="scope">
                        <span>{{scope.row.addTime|dateFormatYYYYMMDD}}/{{scope.row.addUser}}</span></template>
                </el-table-column>
                <el-table-column label="更新时间/人" prop="lastEditTime/editUser"
                                 v-if="!columnsHidden['lastEditTime/editUser']">
                    <template slot-scope="scope"><span>{{scope.row.lastEditTime|dateFormatYYYYMMDD}}/{{scope.row.editUser}}</span>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination :background="true" style="padding: 20px;" :current-page.sync="queryParams.pageNum"
                           :page-size="queryParams.pageSize" layout="prev, pager, next" :total="total"
                           @size-change="(pageSize)=>{$data.queryParams.pageSize=pageSize;dataList=[];getInfoList();}"
                           @current-change="(pageNum)=>{$data.queryParams.pageNum=pageNum;dataList=[];getInfoList();}"></el-pagination>
        </section>
    </div>
</template>
<script>  import { formData, formMethod, PageData } from '@/utils/formcommon';
import { getUrlParam, dateFormatYYYYMMDD } from '@/utils/index';
import { default as FormDialog } from '@codegenarate/mydialogplus';
import * as  api from '@/apis/gTableFeild.api.js';

const dicInner = {
  '___g_field_id': '',
  'g_field_id': 'g_field_id',
  '___g_field_filedName': '',
  'g_field_filedName': 'g_field_filedName',
  '___g_field_filedNameChinese': '',
  'g_field_filedNameChinese': 'g_field_filedNameChinese',
  '___g_field_filedType': '',
  'g_field_filedType': 'g_field_filedType',
  '___g_field_gTableId': '',
  'g_field_gTableId': 'g_field_gTableId',
  '___g_field_delState': '',
  'g_field_delState': 'g_field_delState',
};
export default {
  name: 'gFieldlist',
  data() {
    return {
      api: api,
      dicInner, ...formData,
      queryParams: {
        name: '',
        searchKey: '',
        'id': '',
        'filedName': '',
        'filedNameChinese': '',
        'filedType': '',
        'gTableId': '',
        'delState': '',
        ...PageData,
      },
      lists: [],
      selectRows: [],
      classId: '',
      classIdPath: '',
      className: '',
      loading: false,
      isFold: false,
      tableRowClassName({ row, rowIndex }) {
        if (row.rowType == 'total') {
          return 'total-row';
        }
        return '';
      },
    };
  },
  components: {
    svgIcon: () => import('@codegenarate/svg-icon'),
    dicSelect: () => import('@/components/dicselect.vue'),
    dicTag: () => import('@/components/DicSelect/dic-tag.vue'),
    RightToolbar: () => import('@/components/RightToolbar/index.vue'),
    modify: () => import('./modify'),
  },
  mounted() {
    /* if (this.$props['immediate']) {
       this.getInfoList();
     }*/
  },
  filters: { dateFormatYYYYMMDD: dateFormatYYYYMMDD },
  computed: {},
  watch: {},
  props: {
    immediate: {
      type: [Boolean], default() {
        return true;
      },
    },
    isPage: {
      type: [Boolean],
    },
  },
  methods: {
    ...formMethod,
    /**     * @description:     *
     *    @params _data.gTableId
     *    *    @params _data.pageSize
     *  * @return     */
    initByDialog(_data) {
      this.queryParams.gTableId = _data && _data.gTableId;
      this.queryParams.pageSize = _data && _data.pageSize||10;
      this.getInfoList();
    },
    tableRowClickOnece(row, tableRef, options) {
      var table = this.$refs[tableRef];
      if (options && options.canSelect) {
        var istrue = options.canSelect(row);
        if (!istrue) {
          table && table.toggleRowSelection(row, false);
        }
      }
      table && table.clearSelection();
      table && table.toggleRowSelection(row);
    },
    async triggerModify(row) {
      var self = this;
      var result = await FormDialog({
        width: '888px', title: row && row.id ? '编辑 字段' : '新增 字段',
        data() {
          return {
            ...row,
            gTableId: self.queryParams.gTableId,
          };
        }, components: { modify: () => import('./modify.vue') },
      });
      if (!(result && result.success)) {
        return result;
      }
      this.getInfoList();
    },
  },
};</script>
